package com.tanhua.admin.controller;

import com.tanhua.admin.exception.BusinessException;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.AnalysisSummaryVo;
import com.tanhua.admin.service.AnalysisService;
import com.tanhua.model.vo.CountVo;
import com.tanhua.model.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/dashboard")
public class DashboardController {

    @Autowired
    private AnalysisService analysisService;




    /**
     * 概要统计信息
     */
    @GetMapping("/summary")
    public AnalysisSummaryVo getSummary() {
        AnalysisSummaryVo analysisSummaryVo = analysisService.getSummary();
        return analysisSummaryVo;
    }


    @GetMapping("/users")
    public ResponseEntity findData(@RequestParam("sd") Long sd,
                                   @RequestParam("ed") Long ed,
                                   @RequestParam("type") String type) {

        if(StringUtils.isBlank(type)){
            throw new BusinessException("类型不能为空");
        }

        CountVo countVo = analysisService.findData(sd, ed, type);

        return ResponseEntity.ok(countVo);
    }


}